#!/bin/bash
#copyright by hiboy
source /etc/storage/script/init.sh

link="Advanced_Extensions_app10.asp"
echo $1
if [ "$1"x = "stop"x ] ; then
    nvram set app_27=0 #transocks_enable
    exit
fi

if [ "$1" != "del" ] ; then
eval 'nvram set tablink'$1'='$link';'

nvram set transocks_L2="$(($3 + 10))"
nvram set transocks_L3="$2"
#     show_menu(8,<% nvram_get_x("", "transocks_L2"); %>,<% nvram_get_x("", "transocks_L3"); %>);
fi

get_www ()
{

# 加载程序配置页面
mkdir -p /opt/app/transocks
if [ -f "/tmp/www_asp/Advanced_Extensions_transocksasp" ] ; then
if [ ! -f "/opt/app/transocks/Advanced_Extensions_transocks.asp" ] ; then
	mv -f /tmp/www_asp/Advanced_Extensions_transocksasp /opt/app/transocks/Advanced_Extensions_transocks.asp
else
	rm -f /tmp/www_asp/Advanced_Extensions_transocksasp
fi
fi
if [ ! -f "/opt/app/transocks/Advanced_Extensions_transocks.asp" ] || [ ! -s "/opt/app/transocks/Advanced_Extensions_transocks.asp" ] ; then
	wgetcurl.sh /opt/app/transocks/Advanced_Extensions_transocks.asp "$hiboyfile/Advanced_Extensions_transocksasp" "$hiboyfile2/Advanced_Extensions_transocksasp"
fi
umount /www/Advanced_Extensions_app10.asp
if [ -f "/opt/app/transocks/Advanced_Extensions_transocks.asp" ] ; then
	mount --bind /opt/app/transocks/Advanced_Extensions_transocks.asp /www/Advanced_Extensions_app10.asp
	app10_ver=$(grep 'app10_ver=' /opt/app/transocks/Advanced_Extensions_transocks.asp | awk -F '=' '{print $2;}')
	nvram set app10_ver=${app10_ver}
fi

}

get_app ()
{

# 更新程序启动脚本
[ "$1" = "del" ] && rm -rf /etc/storage/script/Sh58_tran_socks.sh
if [ ! -f "/etc/storage/script/Sh58_tran_socks.sh" ] || [ ! -s "/etc/storage/script/Sh58_tran_socks.sh" ] ; then
	wgetcurl.sh /etc/storage/script/Sh58_tran_socks.sh "$hiboyscript/script/Sh58_tran_socks.sh" "$hiboyscript/script/Sh58_tran_socks.sh"
fi
chmod 777 /etc/storage/script -R
if [ ! -f "/etc/storage/app_9.sh" ] || [ ! -s "/etc/storage/app_9.sh" ] ; then
/etc/storage/script/Sh58_tran_socks.sh update_app
fi

[ "$1" = "del" ] && exit

}

if [ -f /tmp/webui_yes ] ; then
get_www &
get_app $1 &
[ "$1" = "del" ] && exit
fi

